package com.sinog.auth.service;

import com.sinog.auth.entity.AuthUser;
import com.sinog.auth.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @desc 实际获取用户信息接口
 * @author zy
 * @date 2019年8月15日 11点16分
 */
@Service
public class AccountUserDetailService extends BaseUserDetailService {

    @Autowired
    private UserRepository repository;

    /**
     * 描述
     * @param username username
     * @return AuthUser
     */
    @Override
    protected AuthUser getUser(String username) {
        AuthUser authUser = repository.findUserByAccountAndStatIs(username, 1);
        if(null == authUser) {
            throw new UsernameNotFoundException("找不到该用户，用户名：" + username);
        }
        return authUser;
    }
}